﻿using System.Collections;
using System.Collections.Generic;
using Microsoft.Xna.Framework;

namespace block_explorer.Util
{
    public class CellCardinalIterator : IEnumerable
    {
        private List<Vector3> mCells;

        public CellCardinalIterator(Vector3 center)
        {
            mCells = new List<Vector3>();
            mCells.Add(new Vector3(center.X, center.Y, center.Z + 1));
            mCells.Add(new Vector3(center.X + 1, center.Y, center.Z));
            mCells.Add(new Vector3(center.X, center.Y, center.Z - 1));
            mCells.Add(new Vector3(center.X - 1, center.Y, center.Z));
            mCells.Add(new Vector3(center.X, center.Y + 1, center.Z));
            mCells.Add(new Vector3(center.X, center.Y - 1, center.Z));
        }

        public IEnumerator GetEnumerator()
        {
            return mCells.GetEnumerator();
        }
    }

    public class CellSurroundingIterator : IEnumerable
    {
        private List<Vector3> mCells;

        public CellSurroundingIterator(Vector3 center)
        {
            mCells = new List<Vector3>();

            mCells.Add(new Vector3(center.X - 1, center.Y + 1, center.Z + 1));
            mCells.Add(new Vector3(center.X, center.Y + 1, center.Z + 1));
            mCells.Add(new Vector3(center.X + 1, center.Y + 1, center.Z + 1));

            mCells.Add(new Vector3(center.X - 1, center.Y + 1, center.Z));
            mCells.Add(new Vector3(center.X, center.Y + 1, center.Z));
            mCells.Add(new Vector3(center.X + 1, center.Y + 1, center.Z));

            mCells.Add(new Vector3(center.X - 1, center.Y + 1, center.Z - 1));
            mCells.Add(new Vector3(center.X, center.Y + 1, center.Z - 1));
            mCells.Add(new Vector3(center.X + 1, center.Y + 1, center.Z - 1));


            mCells.Add(new Vector3(center.X - 1, center.Y, center.Z + 1));
            mCells.Add(new Vector3(center.X, center.Y, center.Z + 1));
            mCells.Add(new Vector3(center.X + 1, center.Y, center.Z + 1));

            mCells.Add(new Vector3(center.X - 1, center.Y, center.Z));
            /*mCells.Add(new Vector3(center.X, center.Y, center.Z));*/ // dont add the center
            mCells.Add(new Vector3(center.X + 1, center.Y, center.Z));

            mCells.Add(new Vector3(center.X - 1, center.Y, center.Z - 1));
            mCells.Add(new Vector3(center.X, center.Y, center.Z - 1));
            mCells.Add(new Vector3(center.X + 1, center.Y, center.Z - 1));


            mCells.Add(new Vector3(center.X - 1, center.Y - 1, center.Z + 1));
            mCells.Add(new Vector3(center.X, center.Y - 1, center.Z + 1));
            mCells.Add(new Vector3(center.X + 1, center.Y - 1, center.Z + 1));

            mCells.Add(new Vector3(center.X - 1, center.Y - 1, center.Z));
            mCells.Add(new Vector3(center.X, center.Y - 1, center.Z));
            mCells.Add(new Vector3(center.X + 1, center.Y - 1, center.Z));

            mCells.Add(new Vector3(center.X - 1, center.Y - 1, center.Z - 1));
            mCells.Add(new Vector3(center.X, center.Y - 1, center.Z - 1));
            mCells.Add(new Vector3(center.X + 1, center.Y - 1, center.Z - 1));
        }

        public IEnumerator GetEnumerator()
        {
            return mCells.GetEnumerator();
        }
    }
}
